package com.aaa.service.impl;


import com.aaa.entity.RoleMenu;
import com.aaa.mapper.RoleMenuMapper;
import com.aaa.service.RoleMenuService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (TRoleMenu)表服务实现类
 *
 * @author makejava
 * @since 2022-10-26 15:29:39
 */
@Service
public class RoleMenuServiceImpl implements RoleMenuService {
    @Resource
    private RoleMenuMapper roleMenuMapper;
    /**
     * 新增数据
     *
     * @param tRoleMenu 实例对象
     * @return 实例对象
     */
    @Override
    public RoleMenu insert(RoleMenu tRoleMenu) {

        return tRoleMenu;
    }
    /**
     * 修改角色所拥有的菜单业务
     * @param rid
     * @param mids
     * @return
     */
    @Override
    public Boolean updRoleMenu(Integer rid, String mids) {
        //删除该角色所拥有的菜单
        RoleMenu roleMenu = new RoleMenu();
        roleMenu.setRid(rid);
        int delete = roleMenuMapper.delete(roleMenu);
        //将字符串转化为数组
        if(mids!=null){
            String[] midList = mids.split(",");
            for (String mid:midList) {
                int i = Integer.parseInt(mid);
                roleMenu.setMid(i);
                int insert = roleMenuMapper.insert(roleMenu);
            }
        }
        return delete>=0;
    }
}
